function Problem(first, second) {
	this.first = first;
	this.second = second;
	
	this.check = function(val) {
		var expected = Math.round(this.first * this.second);
		if (expected == val) {
			// right!
			return (val > 30) ? 3 : (val > 9) ? 2 : 1;
		} else if (val < 10 && expected >= 10) {
			// partial answer
			return 0;
		} else {
			return -10;
		}
	}
}

function TwoFactorMultiplication(question) {
	this.question = question;
	var num_questions_answered = 0;
	var current_problem;
	
	this.next = function() {
		var first = Math.floor(10*Math.random());
		var second = Math.floor(10*Math.random());
		
		current_problem = new Problem(first, second);		
		this.display(current_problem);
		
		return current_problem;
	}
	
	this.display = function(problem) {
		this.question.text(problem.first + ' x ' + problem.second);
	}
	
	this.check = function(val) {
		var c = current_problem.check(val);
		if (c != 0) num_questions_answered++;
		if (c > 0) num_questions_answered_correctly++;
		return c;
	}
	
	this.reset = function() {
		num_questions_answered = 0;
		num_questions_answered_correctly = 0;
		question.text('? x ?');
	}
	this.questionsAnswered = function() { return num_questions_answered; }
	this.questionsAnsweredCorrectly = function() { return num_questions_answered_correctly; }
}